package com.tjsinfo.tjsoa.addresslist.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.addresslist.bo.IAddressListSystemUserBo;
import com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.system.bo.IDepartmentBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.TSystemDepartment;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.User;

public class toUpdateTjsUserAction extends Action{
	private IAddressListSystemUserBo addressListSystemUserBo;
	private IDepartmentBo departmentBo;
	public void setAddressListSystemUserBo(
			IAddressListSystemUserBo addressListSystemUserBo) {
		this.addressListSystemUserBo = addressListSystemUserBo;
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		String user_id = request.getParameter("user_id");
		String moduleType = request.getParameter("moduleType");
		AddressListSystemUser listUser = addressListSystemUserBo.findByUserId(Integer.valueOf(user_id));
		User user = (User) request.getSession().getAttribute("user");
		String department = "";
		if (user!=null) {
			if (user.getDepartment()!=null) {
				String[] str = user.getDepartment().split(",");
				for (int i = 0; i < str.length; i++) {
					if (str[i]!=null && !"".equals(str[i])) {
						TSystemDepartment de = departmentBo.findById(str[i]);
						if (de!=null) {
							department += de.getDeptName()+",";
						}
					}
				}
			}
			if (!"".equals(department)) {
				department = department.substring(0,department.length()-1);
			}
		}
		listUser.setSector(department);
		
		String nowSQL = ToolKit.getProperties("com/tjsinfo/tjsoa/mail/properties/systemResource.properties", this).getProperty("nowSQL");
		if ("1".equals(nowSQL)) {
			listUser.setCompany("天津市燃气集团有限公司");
		}else if ("2".equals(nowSQL)) {
			listUser.setCompany("天津市燃气集团第一销售分公司");
		}else if ("3".equals(nowSQL)) {
			listUser.setCompany("天津市燃气集团第二销售分公司");
		}else if ("4".equals(nowSQL)) {
			listUser.setCompany("天津市燃气集团第三销售分公司");
		}else if ("5".equals(nowSQL)) {
			listUser.setCompany("天津市燃气集团输配分公司");
		}
		
		request.setAttribute("listUser", listUser);
		request.setAttribute("moduleType", moduleType);
		request.setAttribute("type", "tjsUser");
		return mapping.findForward("ok");
	}

	public void setDepartmentBo(IDepartmentBo departmentBo) {
		this.departmentBo = departmentBo;
	}
}
